package com.nanhai.buddhist.college.module.collegebase.controller.student;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentroll.vo.StudentRollRespVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentroll.vo.StudentRollUpdateReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentroll.vo.StudentUpdateReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.teacher.teacher.vo.AuthLoginReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.teacher.teacher.vo.AuthLoginRespVO;
import com.nanhai.buddhist.college.module.collegebase.convert.studentroll.StudentRollConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.studentroll.StudentRollDO;
import com.nanhai.buddhist.college.module.collegebase.service.studentroll.StudentAuthService;
import com.nanhai.buddhist.college.module.collegebase.service.studentroll.StudentRollService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

/**
 * @author AKai
 * @date 2022/8/28
 */

@Api(tags = "学生端移动端 - 学员信息 ")
@RestController
@RequestMapping("/collegebase/student/move")
@Validated
public class StudentMoveManageController {
    @Resource
    private StudentRollService studentRollService;


    @Resource
    private StudentAuthService studentAuthService;

    @PostMapping("/login")
    @PermitAll
    @ApiOperation("使用账号密码登录")
    @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
        return success(studentAuthService.login(reqVO));
    }


    @GetMapping("/get")
    @ApiOperation("获取个人信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    public CommonResult<StudentRollRespVO> getStudentRoll(@RequestParam("id") String id) {
        StudentRollDO studentRoll = studentRollService.getStudentRoll(id);
        return success(StudentRollConvert.INSTANCE.convert(studentRoll));
    }

    @PostMapping("/update")
    @ApiOperation("完善个人信息")
    public CommonResult<Boolean> updateStudentRoll(@Valid @RequestBody StudentUpdateReqVO updateReqVO) {
        final StudentRollUpdateReqVO studentRollUpdateReqVO = new StudentRollUpdateReqVO();
        BeanUtils.copyProperties(updateReqVO,studentRollUpdateReqVO);
        studentRollService.updateStudentRoll(studentRollUpdateReqVO);
        return success(true);
    }
}
